<template>
  <div class="app-container">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>用户基本信息</span>
            </div>
            <el-form ref="form" :model="userInfo" label-width="80px">
              <el-form-item label="账号">
                <el-input v-model="userInfo.username" :disabled="true"></el-input>
              </el-form-item>
              <el-form-item label="昵称">
                <el-input v-model="userInfo.nickName"></el-input>
              </el-form-item>
              <el-form-item label="手机号">
                <el-input v-model="userInfo.phone"></el-input>
              </el-form-item>
              <el-form-item label="邮箱">
                <el-input v-model="userInfo.email"></el-input>
              </el-form-item>
              <el-form-item label="创建时间">
                <el-input v-model="userInfo.createTime" :disabled="true"></el-input>
              </el-form-item>
              <el-form-item label="密码">
                <el-input type="password" placeholder="为空则不修改" v-model="userInfo.password"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="success" @click="submitForm">保存</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </el-col>
      </el-row>
    </div>
</template>

<script>
import store from '@/store'
import {userPostRequire} from '@/api/user'

export default {
  name: 'home',
  data() {
    return {
      role: store.getters.roles[0],
      userInfo: {}
    }
  },
  created() {
    this.userInfo = store.getters.user
  },
  methods: {
    submitForm() {
      userPostRequire('updateSelfInfo', this.userInfo).then(response => {
        if (response) {
          this.$message({
            message: response.message,
            type: response.status ? 'success' : 'error'
          })
        }
      }).finally(() => {
        window.location.reload();
      })
    }
  }
}
</script>

<style scoped>
.app-container {
  margin-top: 40px;
  margin-left: 120px;
  margin-right: 120px;
}

</style>
